local skill = fk.CreateSkill {
  name = "lvshi__jianxiong",
}

Fk:loadTranslationTable{
  ["lvshi__jianxiong"] = "奸雄",
  [":lvshi__jianxiong"] = "一名角色的回合结束时，若你于此回合造成或受到过伤害，你可获得中央区内当前回合角色选择的一张牌，然后你获得中央区内一张与之颜色不同的牌。",
  ["#lvshi_jianxiong-choose"] = "奸雄：请选择%src获得的牌",
  ["$lvshi__jianxiong1"] = "大忠似奸，留一世功名，前人赞，今人叹，后人羡！",
  ["$lvshi__jianxiong2"] = "乱世称雄，立一方基业，屯万兵，聚百将，拥千城！",
}

local DIY = require "packages/diy_utility/diy_utility"

skill:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      return #player.room.logic:getActualDamageEvents(1, function (e)
        if (e.data.from and e.data.from == player) or e.data.to == player then
          return true
        end
      end, Player.HistoryTurn) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = DIY.getCenterCards(room)
    if #ids == 0 then return end
    local param = {
      target = target,
      max = 1,
      min = 1,
      skill_name = skill.name,
      flag = { card_data = {{skill.name, ids}} },
      prompt = "#lvshi_jianxiong-choose:"..player.id,
    }
    local id = room:askToChooseCards(target, param)
    room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, skill.name, nil, true)
    if #DIY.getCenterCards(room) > 0 then
      local cards = table.filter(DIY.getCenterCards(room), function (cd)
        return Fk:getCardById(cd):compareColorWith(Fk:getCardById(id[1]), true) end)
      if #cards > 0 then
        param = {
          target = player,
          max = 1,
          min = 1,
          skill_name = skill.name,
          flag = { card_data = {{skill.name, cards}} },
          prompt = "#lvshi_jianxiong-choose:"..player.id,
        }
        id = room:askToChooseCards(player, param)
        room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, skill.name, nil, true)
      end
    end
  end,
})

skill:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return skill